// component/dataBoard/stuDataBoard/stuDataBoard.js
const appg = getApp().globalData
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    userType: null,
    uid: null,
    option1: [{
        text: '请假',
        value: 0
      },
      {
        text: '签到',
        value: 1
      },
    ],
    option2: [{
        text: '统计全部',
        value: 'a'
      },
      {
        text: '统计今日',
        value: 'b'
      },
    ],
    value1: 0,
    value2: 'a',
    totalList: null,
    percent: null
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 获取数据
    async getData() {
      this.triggerEvent('Skeleton', {
        loading: true
      })
      const params = {
        uid: this.data.uid,
        userType: this.data.userType,
        type: this.data.value1,
        day: this.data.value2
      }
      const json = await getApp().$axios("/getDataKanBan", "POST", params)
      this.triggerEvent('Skeleton', {
        loading: false
      })
      if (json.status !== 200) {
        wx.showToast({
          title: '查询有误，请重试',
          icon: 'none'
        })
        return
      }
      console.log(json.data);
      if (this.data.value1 == 0) {
        //请假
        //计算百分比
        let res = json.data.holiday_all
        if (res == 0) {
          this.setData({
            percent: 0,
            totalList: json.data
          })
          return
        }
        let num = (json.data.holiday_bj + json.data.holiday_kj + json.data.holiday_sj) / res;
        console.log(this.data,(num*100) ,'学生数据统计的请假率');
        let nums = (num*100).toFixed(2)
        this.setData({
          percent: nums ,
          totalList: json.data
        })
      } else {
        // 签到
        //计算百分比
        let res = json.data.sign_total
        if (res == 0) {
          this.setData({
            percent: 0,
            totalList: json.data
          })
          return
        }
        let num = (json.data.sign_qd) / res;
        console.log(this.data, 23454545);
        let nums = num.toFixed(2)
        this.setData({
          percent: nums * 100,
          totalList: json.data
        })
      }
    },
    //类型变化
    changeValue1(e) {
      const value = e.detail
      this.setData({
        value1: value
      })
      this.getData()
    },
    // 统计时间变化
    changeValue2(e) {
      const value = e.detail
      this.setData({
        value2: value
      })
      this.getData()
    },
  },
  lifetimes: {
    attached: function () {
      this.setData({
        uid: appg.userInfo.id,
        userType: appg.userInfo.identity_ID,
      })
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  // 组件在页面中的生命周期
  pageLifetimes: {
    show: function () {
      this.getData()
    },
    hide: function () {
      // 页面被隐藏
    },
    resize: function (size) {
      // 页面尺寸变化
    }
  }
})